-
Notifications
You must be signed in to change notification settings - Fork 1k
refactor: make resolveBackend side-effect free #9041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
This change refactors resolveBackend to be a pure function that no longer writes to the filesystem. This separation of concerns improves testability and prepares for remote source support where dotenv files may be optional. Key changes: - Remove filesystem writes from resolveBackend - Add writeResolvedEnvsToFile helper in src/functions/env.ts - Update all callsites to handle persistence separately - Add comprehensive unit tests for the new helper - Fix malformed import paths (extra dots) The behavior remains unchanged - new non-internal params are still written to .env files (.env.local for emulator, .env.<projectId> for deployment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @taeold, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request refactors the resolveBackend function to eliminate its filesystem side-effects, making it a pure function. This change is a foundational step towards supporting remote Git sources and improves separation of concerns and testability without introducing user-visible behavior changes.
Highlights
- Pure resolveBackend: The resolveBackend function no longer performs filesystem writes, returning resolved environment variables instead.
- New Helper for Persistence: A new utility function, writeResolvedEnvsToFile, has been introduced in src/functions/env.ts to handle the persistence of resolved environment variables to .env files.
- Updated Call Sites: All existing calls to resolveBackend have been updated to explicitly call the new writeResolvedEnvsToFile helper to maintain the previous behavior of writing environment variables.
- Import Path Corrections: Several malformed import paths (e.g., ../../../api) have been corrected across the codebase.
- New Unit Tests: Comprehensive unit tests have been added for the newly introduced writeResolvedEnvsToFile helper to ensure its correctness.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request is a well-executed refactoring that makes resolveBackend
a pure function by moving filesystem side-effects to a new writeResolvedEnvsToFile
helper. The changes are clean, logical, and well-tested. I have a couple of suggestions to further improve the code quality and maintainability of the new helper function.
- Use proper ParamValue type instead of structural type for better type safety - Remove redundant empty check (writeUserEnvs already handles this) - Rename function from writeResolvedEnvsToFile to writeResolvedParams for clarity - Update tests to use actual ParamValue instances
Refactors
resolveBackend
to be a pure function by removing filesystem calls to write the resolved parameter values.This separation is useful later on as we add support for things like remote source or deploying extensions through the CLI.
resolveBackend
pure - no longer writes to filesystemwriteResolvedParams
helper insrc/functions/env.ts
for param persistenceNo user-visible changes. New params are still written to
.env.local
(emulator) or.env.<projectId>
(deployment).